public class Solution {
    public static void main(String[] args) {
        int[] nums = {3,4,2};
        System.out.println(deleteAndEarn(nums));
    }
    //    删除并获得点数
    public static int deleteAndEarn(int[] nums) {
        int n = 10001;
        int[] arr = new int[n];
        for (int i = 0; i < nums.length; i++) {
            arr[nums[i]] += nums[i];
        }
        int[] f = new int[n];
        int[] g = new int[n];
        f[0] = arr[0];
        for (int i = 1; i < n; i++) {
            f[i] = g[i-1] + arr[i];
            g[i] = Math.max(f[i-1],g[i-1]);
        }
        return Math.max(f[n-1],g[n-1]);
    }
}
